'use strict';

let express = require('express');
let router = express.Router();
let url=require('url');
const qs=require('querystring');
const util=require('util');
let _ = require('lodash')


let requireDir=require('require-dir-all');
let service=requireDir(global.config.web.service,{'recursive':true});

router.use('/*',(req,res)=>{
    let url= req.originalUrl;
    let path=url.substring(1,url.length).replace('/','.');
    let fun=_.get(service,path);
    if(_.isNull(fun)||!_.isFunction(fun)){
        let err = new Error('Not Found');
        err.status = 404;
        res.status(404).send(err);
    }else{
        fun(req,res);
    }
});

module.exports=router;